﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SGRapidForm.Permission.Entity;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Permission.Component;
using Microsoft.Practices.Unity;

namespace SGRapidForm.Permission.Service
{
    /// <summary>
    /// 用户服务
    /// </summary>
    public partial class PermissionService : IPermissionService
    {
        [Dependency]
        public UserComponent UserComponent
        { get; set; }

        public bool User_Add(UserDetails userDetails)
        {
            return this.UserComponent.AddUser(userDetails);
        }

        public bool User_Delete(string keyid)
        {
            return this.UserComponent.DeleteUser(keyid);
        }

        public bool User_Update(UserDetails userDetails)
        {
            return this.UserComponent.UpdateUser(userDetails);
        }

        public List<UserDetails> User_GetAll()
        {
            return this.UserComponent.GetAllUser();
        }

        public List<UserDetails> User_PagingGet(int startRecord, int maxRecords, string sortColumns, string filterConditions)
        {
            return this.UserComponent.PagingGetUsers(startRecord, maxRecords, sortColumns, filterConditions);
        }

        public List<UserDetails> User_FilteredGetAll(String filterConditions)
        {
            return this.UserComponent.User_FilteredGetAll(filterConditions);
           
        }

        public int User_PagingGetCount(string filterConditions)
        {
            return this.UserComponent.PagingGetUsersCount(filterConditions);
        }

        public UserDetails User_GetByKeyid(string keyid)
        {
            return this.UserComponent.GetUserByKeyid(keyid);
        }

        /// <summary>
        /// 批量编辑用户
        /// </summary>
        public bool User_BulkEdit(string columnSettings, string keyids)
        {
            return this.UserComponent.BulkEditUsers(columnSettings, keyids);
        }

        /// <summary>
        /// 批量删除用户
        /// </summary>
        public bool User_BulkDelete(string keyids)
        {
            return this.UserComponent.BulkDeleteUsers(keyids);
        }

        /// <summary>
        /// 用户名是否存在
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool User_IsExist(string userName)
        {
            return UserComponent.IsExist(userName);
        }

        /// <summary>
        /// 根据用户名，查询一位用户
        /// </summary>
        public UserDetails User_GetByName(string userName)
        {
            return this.UserComponent.GetUserByName(userName);
        }

        #region 权限控制

        /// <summary>
        /// 用户是否拥有指定页面的权限
        /// </summary>
        /// <param name="userKeyid">用户Keyid</param>
        /// <param name="pageCode">页面编码</param>
        /// <returns></returns>
        public bool User_HasPagePermission(string userKeyid, string pageCode)
        {
            return this.UserComponent.HasPagePermission(userKeyid, pageCode);
        }

        /// <summary>
        /// 用户是否拥有指定页面上的按钮权限
        /// </summary>
        /// <param name="userKeyid">用户keyid</param>
        /// <param name="pageCode">页面编码</param>
        /// <param name="methodName">方法名称</param>
        /// <returns></returns>
        public bool User_HasButtonPermission(string userKeyid, string pageCode, string serverSideMethod)
        {
            return this.UserComponent.HasButtonPermission(userKeyid, pageCode, serverSideMethod);
        }

        /// <summary>
        /// 获取用户拥有权限的模块
        /// </summary>
        /// <param name="userKeyid">用户Keyeid</param>
        /// <returns></returns>
        public List<ModuleEntity> User_GetModuleBy(string userKeyid)
        {
            return this.UserComponent.GetModuleBy(userKeyid);
        }

        /// <summary>
        /// 获取用户指定模块下拥有权限的一级页面
        /// </summary>
        /// <param name="userKeyid">用户Keyeid</param>
        /// <param name="moduleKeyid">模块Keyeid</param>
        /// <returns></returns>
        public List<PageEntity> User_GetPageBy(string userKeyid, string moduleKeyid)
        {
            return this.UserComponent.GetPageBy(userKeyid, moduleKeyid);
        }

        /// <summary>
        /// 获取用户指定模块下拥有权限的二级页面
        /// </summary>
        /// <param name="userKeyid">用户Keyeid</param>
        /// <param name="moduleKeyid">模块Keyeid</param>
        /// <returns></returns>
        public List<PageEntity> User_GetSecondStagePageBy(string userKeyid, string moduleKeyid)
        {
            return UserComponent.GetSecondStagePageBy(userKeyid, moduleKeyid);
        }

        /// <summary>
        /// 获取用户指定页面下拥有权限的安妮
        /// </summary>
        /// <param name="userKeyid">用户Keyeid</param>
        /// <param name="pageName">页面代码</param>
        /// <returns></returns>
        public List<ButtonEntity> User_GetButtonBy(string userKeyid, string pageCode)
        {
            return this.UserComponent.GetButtonBy(userKeyid, pageCode);
        }

        #endregion

        /// <summary>
        /// 导入用户数据
        /// </summary>
        public bool User_ImportDate(string userName, string password, string realName, string mobilePhone, string email, bool isApproved, bool isLockedOut, string remark, string createName, DateTime createDate, string deptName, string roleName)
        {
            return this.UserComponent.User_ImportDate(userName, password, realName, mobilePhone, email, isApproved, isLockedOut, remark, createName, createDate, deptName, roleName);
        }

        /// <summary>
        /// 清空用户数据
        /// </summary>
        /// <returns></returns>
        public bool User_Clear()
        {
            return UserComponent.User_Clear();
        }



        public List<UserDetails> User_GetUserByButtonPermission(string pagecode, string buttoncode)
        {
             return this.UserComponent.User_GetUserByButtonPermission(pagecode,buttoncode);
        }


        public List<UserDetails> User_GetUserByDeptCode(string deptcode)
        {
            return this.UserComponent.User_GetUserByDeptCode(deptcode); 
        }


        public bool User_ChangePassword(string keyid, string password)
        {
            return this.UserComponent.User_ChangePassword(keyid, password);
        }
    }
}